package priv.xakml.demo.boot19serailnumber;

import com.jcex.serialnumber.SerialNumberClient;
import com.jcex.serialnumber.SerialNumberResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("api/default")
public class DefaultController {

    SerialNumberClient client = new SerialNumberClient("http://jcex.f3322.net:9016", "AK5F259062D2C34D319A13A8848FA4ABB9", "AS15A1800175BA4F1B8F891F61841AA94A");

    @GetMapping("serialnumber")
    public String getSerialNumber() throws NoSuchAlgorithmException {
        int capacity = 50;
        String serialNumber = "";
            SerialNumberResult serialNumberResult = client.getSerialNumber();
            if (serialNumberResult.Success) {
                serialNumber = serialNumberResult.Data.SerialNo;
                System.out.println(serialNumberResult.Data);
            } else {
                System.out.println(serialNumberResult.Msg);
                return serialNumberResult.Msg;
            }
//            if(i != 1 && i % capacity == 0){;
//                cacheNumbers.clear();
//                writeNumbersToFile(cacheNumbers)
//            }
        return serialNumber;
    }
}
